package com.edu.zm;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;

public class LoginInter {

	public static void main(String[] args) {

		// 加载测试
		testMain();

	}

	private static void testMain() {
		ChoiceUI ch = new ChoiceUI();
		Scanner sc = new Scanner(System.in);
		while (true) {
			ch.logon();
			int choiceA = sc.nextInt();
			if (choiceA == 1) {
				boolean isLogin = true;
				boolean isStudent = true;
				while (isLogin) {
					System.out.println("输入學生ID：");
					String login = sc.next();
					System.out.println("输入登录密码：");
					String loginPswd = sc.next();
					String strSql = "select * from Educational where student_id=" + login + " and student_pasd="
							+ loginPswd;
					/**
					 * 通过学号ID查找对应的密码， 检查二者是否匹配
					 * 
					 * String strSql1="select student_pasd from Educational where
					 * student_id="+login; try { //获取通过学生id查询到的密码字段 ResultSet res=
					 * Dbconnect.getConn().createStatement().executeQuery(strSql1);
					 * //通过学号ID查找对应的密码二者进行匹配 /* if(res.getObject(1)==loginPswd) { } } catch
					 * (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }
					 */

					if (Dbconnect.simplePlant(OperaDB.class).getList(strSql, Educational.class).size() > 0) {
						while (isStudent) {
							ch.studentLogin();
							// 选择学生登录的功能
							int chocieA1 = sc.nextInt();
							switch (chocieA1) {
							default:
								isStudent = false;
								break;
							}
						}
						// 当按任意键退出，退回到选择师生登录界面
						isLogin = false;
					} else {
						System.out.println("账号或密码错误请重新输入！！是否继续登录【1.是/2.否】");
						isLogin = sc.nextInt() == 1 ? true : false;
					}
				}
			} else if (choiceA == 2) {
				boolean isTeacher = true;
				boolean isLogin = true;
				while (isLogin) {
					System.out.println("输入登录账户：");
					String login = sc.next();
					System.out.println("输入登录密码：");
					int loginPswd = sc.nextInt();
					if (login.equals("admin") && loginPswd == 1234) {
						while (isTeacher) {
							ch.teacherLogin();
							// 选择老师登录的功能
							int chocieA1 = sc.nextInt();
							switch (chocieA1) {
							case 1:
								// 添加学生信息选项
								int up1 = Dbconnect.simplePlant(OperaDB.class).insert();
								System.out.println("已添加" + up1 + "行");
								// 跳转回老师登录功能
								break;
							case 2:
								OperaDB.queryDb();
								// 跳转回老师登录功能
								break;
							case 3:
								Dbconnect.simplePlant(OperaDB.class).upadate();
								break;
							case 4:
								Dbconnect.simplePlant(OperaDB.class).deleteStuInfor();
								break;
							case 5:
								Dbconnect.simplePlant(OperaDB.class).saveStuInfo();
								break;
							case 6:
								Dbconnect.simplePlant(OperaDB.class).loadStuInfo();
								break;
							// 按任意键退出
							default:
								isTeacher = false;
								break;
							}
						}
						// 当按任意键退出，退回到选择师生登录界面
						isLogin = false;
					} else {
						System.out.println("账号或密码错误请重新输入！！是否继续登录【1.是/2.否】");
						isLogin = sc.nextInt() == 1 ? true : false;
					}
				}
			} else {
				System.out.println("退出登录！");
				break;
			}

		}
	}
}
